/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package coderbyte;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author ascorbin
 */
public class AlternativeMedium {

    /**
     * finds the greatest common factor of the parameters by determining the
     * number of divisors, this challenge is one possible solution of the medium
     * division challenge
     *
     * @param arg1 number
     * @param arg2 number
     * @return greatest common factor
     */
    int Division(int arg1, int arg2) {
        int res;
        List<Integer> dvsrsList1 = new ArrayList<>();
        List<Integer> dvsrsList2 = new ArrayList<>();

        for (int i = 1; i < arg1; i++) {
            if (arg1 % i == 0) {
                dvsrsList1.add(i);
            }
        }
        for (int i = 1; i < arg2; i++) {
            if (arg2 % i == 0) {
                dvsrsList2.add(i);
            }
        }
        Collections.sort(dvsrsList1, Collections.reverseOrder());
        Collections.sort(dvsrsList2, Collections.reverseOrder());
        if (dvsrsList1.size() <= dvsrsList2.size()) {
            dvsrsList2.retainAll(dvsrsList1);
            res = dvsrsList2.get(0);
        } else {
            dvsrsList1.retainAll(dvsrsList2);
            res = dvsrsList1.get(0);
        }

        return res;
    }
}
